SproutCore 1.5.pre.4 - TemplateView is Here

written by TomHuda

Today we released the fourth pre-release of SproutCore 1.5, moving us a step closer to a final release next month. This version has a bunch of new features, including the initial release of TemplateView, which makes it easier to build SproutCore applications in a more conventional HTML style.

You can get the prerelease gem by typing:

<code>gem install sproutcore --pre
</code>

Here are some of the improvements:

SC.TemplateView

Template views can form the basis of an entire application, or can integrate seamlessly with an existing SproutCore view hierarchy. This release incorporates support for the Handlebars template engine in both SproutCore itself and the SproutCore build tools.

Templates are HTML files with special tags included that can reference properties on your view or other objects. These properties can be setup as bindings so the HTML will automatically update whenever the properties change.

In general you define templates in your resources/templates directory and then use SC.TemplateView to render them. Working with SC.TemplateView is just like any other view except you specify a templateName property instead of a render method. For instance, if you had a template at resources/templates/post_item.handlebars, you could use it in your app with something like:

MyApp.PostItemView = SC.TemplateView.extend({
  templateName: 'post_item'
});

View Mixins

SproutCore 1.5 also comes with two new mixins for use with SC.TemplateView: SC.TextFieldSupport and SC.CheckboxSupport. You can apply these mixins to any view whose HTML includes the relevant HTML element:

MyApp.CreatePostView = SC.TemplateView.extend(SC.TextFieldSupport, {
  insertNewline: function() {
    // instead of directly observing the keyUp event and filtering
    // by keycode, you can use a higher level event
  }
});

MyApp.StarPostView = SC.TemplateView.extend(SC.CheckboxSupport, {
  // bind the value of the checkbox to a controller
  valueBinding: 'MyApp.postController.isStarred',

  valueDidChange: function() {
    // observe a change to a SproutCore property, rather than
    // observing the DOM directly
  }.observes('value')
});

In general these mixins are intended for use with TemplateView-driven apps that do not require the full richness of the built-in SC.TextFieldView and SC.CheckboxView.

Handlebars and Helpers

This release includes a new template rendering engine called Handlebars. Handlebars is based on the popular Mustache template engine, but is much faster and capable of supporting plugins (which is what we use to support bindings).

We’ve added several helpers to Handlebars to allow you to assign views to your HTML and have it update when properties change.

You can use the view block helper to assign HTML to a SproutCore view class, and the bind helper to tell SproutCore to print the value of a property (and update it when it changes). For example:

<code>{{#view "MyApp.PostView"}}
    <h1>{{bind "title"}}</h1>
{{/view}}
</code>

The bind helper works in block form too:

<code>{{#bind "content"}}
    <h1>{{title}}</h1>
    <div>{{{body}}}</div>
{{/bind}}
</code>

Whenever the underlying property changes, SproutCore will replace the contents of the block by re-rendering it with the new value of the property. This can eliminate a lot of glue code for views.

You can also use the collection helper to display a template for each item in an enumerable:

<code>{{#collection "MyApp.MyTemplateCollectionView"}}
    <b>{{bind "content.title"}}</b>
{{/collection}}
</code>

Then, just bind the content property of the collection to an enumerable:

<code>MyApp.MyTemplateCollectionView =
  SC.TemplateCollectionView.extend({
    contentBinding: 'MyApp.myArrayController'
  });
</code>

Experimental Framework

As of SproutCore 1.5, we will include new, in-progress features as part of the experimental framework. It will not be included by default, and you can add any experimental features to your Buildfile:

The purpose of this change is to make it easier for us to include new features from the community.

<code>config :all, :required => [:sproutcore,
            "sproutcore/experimental/device_motion"]
</code>

Core Foundation

In order to make it easier to use a smaller subset of SproutCore in constrained environments, this release also includes a new core_foundation framework that contains a basic SproutCore environment, with no extras. You can use it by specifying it in your Buildfile:

<code>config :all, :required => "sproutcore/core_foundation"

# if you want to include other frameworks normally included by :sproutcore

config :all, :required => ["sproutcore/core_foundation", "sproutcore/datastore"]
</code>

You can also use SC.CoreView rather than SC.View, which is a significantly stripped down version of a SproutCore view. However, it is missing quite a few features you probably expect (like layout), so it probably makes sense to wait until the release candidates of SproutCore 1.5, when we’ll have much better appropriate usage information.

Other Improvements

SC.ImageView will use a <canvas> tag on platforms that support it, which improves performance significantly.

SC.SegmentedView now creates an overflow menu if there are too many segments to display. Class names for SC.SegmentedView have been cleaned up. You may need to update your CSS if you were theming SC.SegmentedView.

You can now observe the contents of enumerables using the special @each key.

<code>SC.postsController = SC.ArrayController.create({
    isDoneDidChange: function() {
        // this observer is triggered when:
        // * an element is added
        // * an element is removed
        // * any child element's `isDone` property changes
    }.observes('.@each.isDone')
});
</code>

Dependent keys can accept property paths. For example, you can say .property(‘foo.bar’), and it will be invalidated if the bar property of foo changes. This works with the new @each property as well.

We deprecated SC.viewportOffset(). Please use SC.offset() instead, which is more explicit about what it returns and has more features.

SC.browser now detects Android devices.

SC.device.orientation now works reliably on desktop, iOS, and Android 2.1 and above.

The experimental framework includes support for gyroscope information, if provided by the browser. This is in the sproutcore/experimental/device_motion framework.

Tom and Yehuda showing off (a) their general awesomeness, but more importantly, (b) their nifty n

written by admin

			![](http://blog.sproutcore.com/photo/1280/3349083828/1/tumblr_lgs47g58CY1qzdemz)
		



		


			![](http://blog.sproutcore.com/photo/1280/3349083828/2/tumblr_lgs47g58CY1qzdemz)

Tom and Yehuda showing off (a) their general awesomeness, but more importantly, (b) their nifty new SproutCore t-shirts :)

As previously mentioned, we’ll be sending these to our fantastic SproutCore Guides contributors, so if you haven’t participated yet, here’s a bit of motivation. 

We’ll also be distributing a few at the upcoming San Francisco and New York Meetups – RSVP now!

More Meetup Goodness!

written by lsilber

There’s been a lot of movement on the SproutCore Meetups front as of late; if you haven’t been to a Meetup yet, you definitely want to try and make it out. It’s a great opportunity to meet other talented developers, learn about the ins and outs, and even better, show off your code. We’ve got a number of Meetups happening soon, so find the one nearest you!

> > **[New York](http://www.meetup.com/Sproutcore-NYC/events/16478236/) **February 23 > > > > The first New York City SproutCore Meetup kicks off with a visit from SproutCore creator Charles Jolley. He'll talk a bit about the history of SproutCore, the current state of affairs, and the exciting things on the way. [RSVP here](http://www.meetup.com/Sproutcore-NYC/events/16478236/). > > > > **[Toronto](http://www.meetup.com/HTML5-Web-App-Developers/events/16073084/) **February 24 > > > > The Toronto HTML 5 group will be switching gears for their February Meetup, for _An Evening with SproutCore_. Core Team Member Michael Cohen will be on hand to walk folks through some SproutCore design concept basics, and to show off some great production SproutCore apps, like the recently released NPR app and Eloqua10. [RSVP here](http://www.meetup.com/HTML5-Web-App-Developers/events/16073084/). > > > > **[Chicago](http://www.meetup.com/sproutcore-chicago/events/16344211/) **March 3 > > > > The SproutCore Chicago group kicks off their series with a great talk by Jeff O'Dell on Lebowski, the top SproutCore testing framework out there. [RSVP here](http://www.meetup.com/sproutcore-chicago/events/16344211/).   > > > > **[San Francisco](http://www.meetup.com/sproutcore/events/16508797/) **March 16 > > > > The second 2011 edition of the SF SproutCore Meetup will feature two great talks. First up is Core Team Member Tom Dale, talking about the SproutCore View Layer, and second, Core Team Member Yehuda Katz will present an update on the much-anticipated release of Amber. [RSVP here](http://www.meetup.com/sproutcore/events/16508797/). > >

All of the meetups have limited seating, and sponsored food and drinks. Past Meetups have been filling up fast, so be sure to RSVP now! See you all there… 

SproutCore 1.5 Prerelease

written by TomHuda

We’ve just released a 1.5 pre-release gem. There’s still a lot of flux and it’s not considered stable so we don’t recommend it for production apps, but if you’d like a sneak peek of the new features take a look. To install just run

<code>gem install sproutcore --pre</code>

We’ll be releasing more information about the new features in 1.5 over the coming weeks so keep an eye out.

SproutCore User Groups and Docs Hackathon!

written by admin

Things are taking off for folks interested in starting local user groups! 2009 saw the resurgence of the San Francisco group, and thus far, just in January, groups have been announced in both New York and Chicago, with dates on the way. If you’re interested in starting a group in your area, we’d love to help you get off your feet! Send us an email and we’ll get in touch :)

The next edition of the San Francisco User Group will be all about the docs—we’ll be gathering, hackathon style, to work on general documentation and the new SproutCore Guides. There’s been a major recent interest in getting our documentation resources up to snuff to keep up with the growing number of new developers looking to dive in, and this is the perfect way to keep the momentum going.

There’ll be a small, but not too small group gathering on-site in San Francisco, and a number of folks joining us via the web. We’ll start with some intros, talk about how to divvy up the work, and then pair off. SproutCore Core Team members Yehuda Katz and Peter Wagenet will be on-site and online leading the festivities and answering questions.

If you’d like to join us, on or off site, be sure to RSVP. To attend in person (there will be pizza and drinks, courtesy of the folks at Strobe), hit the main Meetup page. To join us remotely (and there are, alas, only a small number of spots, to be sure we can work with everyone in attendance), there’s a separate Meetup invite for you.